import javax.swing.JFrame;
import java.awt.event.*;

public class Test extends JFrame
{

	public Test()
	{
		this.addWindowListener(new WindowAdapter()
	   {
			public void windowClosing(WindowEvent e)
			{
				System.out.println("Funcionou!");
			}
	   });
	}

	public static void main(String args[])
	{
		Test application = new Test();
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		application.setVisible(true);
	}
}